/**
 * 
 */
package org.ranch.web.midlet;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Date;

/**
 * @author Jmpango
 * 
 */
public class MidletAnimal {

    private String id;
    private String type;
    private String earTag;
    private int weight;
    private String name;
    private String healthStatus;
    private Date dateOfBirth;
    private String color;
    private String Kraal;
    private Date purchaseDate;
    private String description;
    private String breed;
    private int birthWeight;
    private int sellingPrice;
    private int buyingPrice;
    private String status;
    
    public MidletAnimal (){}

    public MidletAnimal(String id, String type, String earTag, int weight, String name,
	    String healthStatus, Date dateOfBirth, String color, String kraal, Date purchaseDate,
	    String description, String breed, int birthWeight, int sellingPrice, int buyingPrice,
	    String status) {
	setId(id);
	setType(type);
	setEarTag(earTag);
	setWeight(birthWeight);
	setName(name);
	setHealthStatus(healthStatus);
	setDateOfBirth(dateOfBirth);
	setColor(color);
	setKraal(kraal);
	setPurchaseDate(purchaseDate);
	setDescription(description);
	setBreed(breed);
	setBirthWeight(birthWeight);
	setSellingPrice(sellingPrice);
	setBuyingPrice(buyingPrice);
	setStatus(status);
    }

    public byte[] serializer() throws IOException {

	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	DataOutputStream dos = new DataOutputStream(baos);

	String recordValue = "";
	
	recordValue += getId() + ":";
	recordValue += getEarTag() + ":";
	recordValue += getWeight() + ":";
	recordValue += getName() + ":";
	recordValue += getKraal() + ":";
	recordValue += getDescription() + ":";
	recordValue += getBirthWeight() + ":";
	recordValue += getSellingPrice() + ":";
	recordValue += getBuyingPrice() + ":";
	dos.writeUTF(recordValue);
	dos.flush();

	recordValue = "";
	dos.close();
	baos.close();

	return baos.toByteArray();
    }

    public MidletAnimal deserializer(byte[] b) throws IOException, ClassNotFoundException {
	ByteArrayInputStream bais = new ByteArrayInputStream(b);
	DataInputStream dis = new DataInputStream(bais);

	bais.reset();
	dis.close();
	bais.close();
	return this;
    }

    /**
     * @return the id
     */
    public String getId() {
	return id;
    }

    /**
     * @param id
     *            the id to set
     */
    public void setId(String id) {
	this.id = id;
    }

    /**
     * @return the type
     */
    public String getType() {
	return type;
    }

    /**
     * @param type
     *            the type to set
     */
    public void setType(String type) {
	this.type = type;
    }

    /**
     * @return the earTag
     */
    public String getEarTag() {
	return earTag;
    }

    /**
     * @param earTag
     *            the earTag to set
     */
    public void setEarTag(String earTag) {
	this.earTag = earTag;
    }

    /**
     * @return the weight
     */
    public int getWeight() {
	return weight;
    }

    /**
     * @param weight
     *            the weight to set
     */
    public void setWeight(int weight) {
	this.weight = weight;
    }

    /**
     * @return the name
     */
    public String getName() {
	return name;
    }

    /**
     * @param name
     *            the name to set
     */
    public void setName(String name) {
	this.name = name;
    }

    /**
     * @return the healthStatus
     */
    public String getHealthStatus() {
	return healthStatus;
    }

    /**
     * @param healthStatus
     *            the healthStatus to set
     */
    public void setHealthStatus(String healthStatus) {
	this.healthStatus = healthStatus;
    }

    /**
     * @return the dateOfBirth
     */
    public Date getDateOfBirth() {
	return dateOfBirth;
    }

    /**
     * @param dateOfBirth
     *            the dateOfBirth to set
     */
    public void setDateOfBirth(Date dateOfBirth) {
	this.dateOfBirth = dateOfBirth;
    }

    /**
     * @return the color
     */
    public String getColor() {
	return color;
    }

    /**
     * @param color
     *            the color to set
     */
    public void setColor(String color) {
	this.color = color;
    }

    /**
     * @return the kraal
     */
    public String getKraal() {
	return Kraal;
    }

    /**
     * @param kraal
     *            the kraal to set
     */
    public void setKraal(String kraal) {
	Kraal = kraal;
    }

    /**
     * @return the purchaseDate
     */
    public Date getPurchaseDate() {
	return purchaseDate;
    }

    /**
     * @param purchaseDate
     *            the purchaseDate to set
     */
    public void setPurchaseDate(Date purchaseDate) {
	this.purchaseDate = purchaseDate;
    }

    /**
     * @return the description
     */
    public String getDescription() {
	return description;
    }

    /**
     * @param description
     *            the description to set
     */
    public void setDescription(String description) {
	this.description = description;
    }

    /**
     * @return the breed
     */
    public String getBreed() {
	return breed;
    }

    /**
     * @param breed
     *            the breed to set
     */
    public void setBreed(String breed) {
	this.breed = breed;
    }

    /**
     * @return the birthWeight
     */
    public int getBirthWeight() {
	return birthWeight;
    }

    /**
     * @param birthWeight
     *            the birthWeight to set
     */
    public void setBirthWeight(int birthWeight) {
	this.birthWeight = birthWeight;
    }

    /**
     * @return the sellingPrice
     */
    public int getSellingPrice() {
	return sellingPrice;
    }

    /**
     * @param sellingPrice
     *            the sellingPrice to set
     */
    public void setSellingPrice(int sellingPrice) {
	this.sellingPrice = sellingPrice;
    }

    /**
     * @return the buyingPrice
     */
    public int getBuyingPrice() {
	return buyingPrice;
    }

    /**
     * @param buyingPrice
     *            the buyingPrice to set
     */
    public void setBuyingPrice(int buyingPrice) {
	this.buyingPrice = buyingPrice;
    }

    /**
     * @return the status
     */
    public String getStatus() {
	return status;
    }

    /**
     * @param status
     *            the status to set
     */
    public void setStatus(String status) {
	this.status = status;
    }

}
